import { createStore } from 'vuex'
import { getItem, setItem } from '@/utils/stroge'
import { getInfo, policyTypeList } from '@/apis/index'

export default createStore({
  state: {
    // 头部标题
    headerTitle: getItem('headerTitle') || '财专专属财税机器人',
    // 左侧菜单
    navList: getItem('navList') || [],
    policyType: getItem('policyType') || [],

    // 是否要回到首页
    isScreen: 0
  },
  mutations: {
    setHeaderTitle(state, value){
      state.headerTitle = value
      setItem('headerTitle', state.headerTitle)
    },
    setNavList(state, value){
      state.navList = value
      setItem('navList', state.navList)
    },
    setPolicyType(state, value){
      state.policyType = value
      setItem('policyType', state.policyType)
    },
    setIsScreen(state){
      state.isScreen = state.isScreen + 1
    }
  },
  actions: {
    getHeaderTitle(context){
      getInfo().then(res => {
        context.commit('setHeaderTitle', res.data.robotName)
        context.commit('setNavList', res.data.dataList)
      })
    },
    getPolicyType(context){
      policyTypeList().then(res => {
        res.data.unshift({
          id: 0,
          name:'全部'
        })
        context.commit('setPolicyType', res.data)
      })
    }
  },
  getters: {
  },
  modules: {
  }
})
